/**
 * StudentService.java
 */
package pers.gs.service.Impl;

import pers.gs.Dao.IStudentDao;
import pers.gs.Dao.Impl.StudentDaoImpl;
import pers.gs.Entity.Student;
import pers.gs.service.IStudentService;

import java.util.List;

/**
 * 业务逻辑层
 */
public class StudentServiceImpl implements IStudentService {
    IStudentDao studentDaoImpl = new StudentDaoImpl();

    //根据学号，查询学生信息
    public Student queryStudentBySno(String sno){
            Student student = studentDaoImpl.queryStudentBySno(sno);
            return student;
    }

    //查询所有学生信息
    public List<Student> queryAllStudent(){
        List<Student> studentList= studentDaoImpl.queryAllStudent();
        return  studentList;
    }

    //修改学生信息
    public  boolean updateStudentBySno(String sno,Student student){
        if (!studentDaoImpl.isExist(sno)){//学生信息不存在
            return false;
        }else {//学生信息存在
            return studentDaoImpl.updateStudentBySno(sno,student);
        }
    }

    //删除学生信息
    public boolean deleteStudentBySno(String sno){

        //判断该学生是否存在。
        if (!studentDaoImpl.isExist(sno)){
            return false;
        }else {
            return studentDaoImpl.deleteStudentBySno(sno);
        }
    }

    //新增学生信息
    public boolean addStudent(Student student){
        if (!studentDaoImpl.isExist(student.getSno())){//如果该学生信息不存在
            return studentDaoImpl.addStudent(student);//新增信息成功
        }else {//该学生信息存在
            return false;//新增信息失败
        }
    }
}
